home *** CD-ROM | disk | FTP | other *** search
/ MacFormat España 27 / MacFormat n. 27 (Spain) / Mac Format 26.bin / Shareware / Juegos / numerarium / numerarium.dxr / 00001.ls next >
Encoding:
Text File  |  1997-02-16  |  27.9 KB  |  978 lines

  1. global toDrawFromSet, lengthtoDrawFromSet, nrOfStims, stimSet, targetnr, bestresultSoFar, bestresultSoFarStr, nrofcalculations, nrbuttontable, currentStep, currentInputStatus, zerobuttonsnr, zerooperatorsnr, firstbuttonloch, hdistancebetweenbuttons, firstbuttonlocv, firstnrloch, firstnrlocv, vdistancebetweenbuttons, zeroClearsnr, operatorList, operand1, operand2, operator, operatorindex, tempoperatorindex, heaven, tempresultbuttonsnr, tempresultnrsnr, connectorsnr, tempoperatorsnr, spinnersnr, connectorlocs, connectorcastnums, opconnectorcastnums, calcIsRunningP, calculatorsnr, nrOfCalcsSnr, nrOfCalcsLoc, foundItIsSalient, foundItButtonNr, clockIsActiveP, fillbarsnr, timeAtReset, ticksPassed, maxlengthFillbar, maxsecssnr, deadlinePassed, nrOfSecsInMAxSecs, clocksnr, timeOutLinesnr, menusnr, score, hscoreFromFile, timeOnStartCalculator, calcAlwaysP, menuVisibleP, wrappedHOffset, wrappedVOffset, scorepossibleThisRoundP, lastbutton, operand2index, findProblemInDatabaseP, selectableProblems, fakesolution, justAborted, firstabortprocessed, easyP, minusalertGivenP, dividealertGivenP, initializedP, switchedP
  2.  
  3. on startMovie
  4.   set the text of member "letsplay" to RETURN & " " & RETURN
  5.   set switchedP to 1
  6.   SETALLTEXTCORRECT()
  7.   puppetSound("kithara.aif")
  8.   set the stageColor to 210
  9.   set score to 0
  10.   put "0" into field "scorestr"
  11.   set initializedP to 0
  12. end
  13.  
  14. on startinit
  15.   if initializedP then
  16.     return 
  17.   else
  18.     startplay()
  19.     set initializedP to 1
  20.     set the text of member "letsplay" to RETURN & "LET'S PLAY!" & RETURN
  21.   end if
  22. end
  23.  
  24. on doneWithInit
  25.   go("startplay")
  26. end
  27.  
  28. on makesureSoundPlays
  29.   if not soundBusy(1) then
  30.     puppetSound("kithara.aif")
  31.   end if
  32. end
  33.  
  34. on clickOnEasy
  35.   set switchedP to 1
  36.   set easyP to 1
  37.   set toDrawFromSet to [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 15, 20, 25]
  38. end
  39.  
  40. on clickOnhard
  41.   set switchedP to 1
  42.   set easyP to 0
  43.   set toDrawFromSet to [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 15, 20, 25, 50, 75, 100]
  44. end
  45.  
  46. on SETALLTEXTCORRECT
  47.   repeat with i = 1 to 7
  48.     if i < 7 then
  49.       set whichCastMember to "stim" & string(i)
  50.     else
  51.       set whichCastMember to "tempresult"
  52.     end if
  53.     set the textHeight of member whichCastMember to 16
  54.     set the textAlign of member whichCastMember to "center"
  55.     set the textFont of member whichCastMember to "Monaco"
  56.     set the textSize of member whichCastMember to 12
  57.     set the textStyle of member whichCastMember to "plain"
  58.   end repeat
  59.   set the textHeight of member "tempresult" to 12
  60.   set whichCastMember to "targetfield"
  61.   set the textAlign of member whichCastMember to "center"
  62.   set the textFont of member whichCastMember to "Monaco"
  63.   set the textSize of member whichCastMember to 24
  64.   set the textStyle of member whichCastMember to "bold"
  65.   set whichCastMember to "calculationsfield"
  66.   set the textAlign of member whichCastMember to "left"
  67.   set the textFont of member whichCastMember to "Geneva"
  68.   set the textSize of member whichCastMember to 6
  69.   set the textStyle of member whichCastMember to "plain"
  70.   set whichCastMember to "showprogress"
  71.   set the textAlign of member whichCastMember to "left"
  72.   set the textFont of member whichCastMember to "Geneva"
  73.   set the textSize of member whichCastMember to 12
  74.   set the textStyle of member whichCastMember to "plain"
  75. end
  76.  
  77. on startplay
  78.   set wrappedHOffset to 0
  79.   set wrappedVOffset to -5
  80.   set the stageColor to 247
  81.   startTimer()
  82.   set nrOfStims to 6
  83.   set zerobuttonsnr to 20
  84.   set zerooperatorsnr to 4
  85.   set zeroClearsnr to 10
  86.   set spinnersnr to 42
  87.   set toDrawFromSet to [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 15, 20, 25, 50, 75, 100]
  88.   set lengthtoDrawFromSet to count(toDrawFromSet)
  89.   initializeRomans()
  90.   set operatorList to ["+", "-", "x", ":"]
  91.   repeat with n = 1 to nrOfStims
  92.     puppetSprite(zerobuttonsnr + ((n - 1) * 2) + 1, 1)
  93.     puppetSprite(zerobuttonsnr + (n * 2), 1)
  94.     set the visible of sprite (zerobuttonsnr + ((n - 1) * 2) + 1) to 1
  95.     set the visible of sprite (zerobuttonsnr + (n * 2)) to 1
  96.   end repeat
  97.   repeat with n = 1 to count(operatorList)
  98.     puppetSprite(zerooperatorsnr + n, 1)
  99.   end repeat
  100.   set tempresultbuttonsnr to 9
  101.   set tempresultnrsnr to 10
  102.   puppetSprite(tempresultbuttonsnr, 1)
  103.   puppetSprite(tempresultnrsnr, 1)
  104.   spriteBox(tempresultnrsnr, 1100, 1100, 1191, 1130)
  105.   set connectorsnr to 19
  106.   set tempoperatorsnr to 20
  107.   puppetSprite(connectorsnr, 1)
  108.   puppetSprite(tempoperatorsnr, 1)
  109.   puppetSprite(spinnersnr, 1)
  110.   set calculatorsnr to 3
  111.   puppetSprite(calculatorsnr, 1)
  112.   set nrOfCalcsSnr to 4
  113.   puppetSprite(nrOfCalcsSnr, 1)
  114.   set nrOfCalcsLoc to point(22, 468)
  115.   initRadioButtons()
  116.   set firstbuttonloch to 122
  117.   set firstbuttonlocv to 117
  118.   set hdistancebetweenbuttons to 84
  119.   set vdistancebetweenbuttons to 52
  120.   set firstnrloch to 58
  121.   set firstnrlocv to 95
  122.   set heaven to point(1000, 1000)
  123.   set clockIsActiveP to 0
  124.   set fillbarsnr to 33
  125.   puppetSprite(fillbarsnr, 1)
  126.   set the visible of sprite fillbarsnr to 0
  127.   set maxsecssnr to 34
  128.   puppetSprite(maxsecssnr, 1)
  129.   set the visible of sprite maxsecssnr to 0
  130.   set timeOutLinesnr to 44
  131.   puppetSprite(timeOutLinesnr, 1)
  132.   set the visible of sprite timeOutLinesnr to 0
  133.   set maxlengthFillbar to 569 - 47
  134.   set clocksnr to 1
  135.   puppetSprite(clocksnr, 1)
  136.   set calcAlwaysP to 0
  137.   set menusnr to 46
  138.   set menuVisibleP to 0
  139.   puppetSprite(menusnr, 1)
  140.   if initializedP then
  141.     feedbackForSpinning()
  142.     resetbuttons()
  143.   else
  144.     createbuttons()
  145.   end if
  146.   initAllVars()
  147.   showfirstRow()
  148.   initDatabase()
  149. end
  150.  
  151. on spinAgain
  152.   if currentInputStatus = #waitForOperand2 then
  153.     unpressOperatorButton(operatorindex)
  154.   end if
  155.   feedbackForSpinning()
  156.   if initializedP then
  157.     resetbuttons()
  158.   else
  159.     createbuttons()
  160.   end if
  161.   put "before initAllVars" & the ticks
  162.   initAllVars()
  163.   put "before showfirstRow" & the ticks
  164.   showfirstRow()
  165.   set old to the stageColor
  166.   set the stageColor to 247
  167.   updateStage()
  168.   set the stageColor to old
  169.   put "before provideTheTask" & the ticks
  170.   provideTheTask()
  171.   put "after provideTheTask" & the ticks
  172.   if calcAlwaysP then
  173.     clickOnCalculator()
  174.   end if
  175. end
  176.  
  177. on unpuppetall
  178.   repeat with i = 1 to 48
  179.     puppetSprite(i, 0)
  180.   end repeat
  181. end
  182.  
  183. on initAllVars
  184.   set justAborted to 0
  185.   repeat with n = 1 to nrOfStims - 1
  186.     puppetSprite(zeroClearsnr + n, 1)
  187.     set the visible of sprite (zeroClearsnr + n) to 0
  188.     set the castNum of sprite (zeroClearsnr + n) to cast "clearButtonUnPressed"
  189.   end repeat
  190.   set connectorlocs to []
  191.   set connectorcastnums to []
  192.   set opconnectorcastnums to []
  193.   set the loc of sprite tempresultbuttonsnr to heaven
  194.   set the loc of sprite tempresultnrsnr to heaven
  195.   set the loc of sprite tempoperatorsnr to heaven
  196.   set the loc of sprite connectorsnr to heaven
  197.   set calcIsRunningP to 0
  198.   set the loc of sprite nrOfCalcsSnr to heaven
  199.   set currentStep to 1
  200.   set currentInputStatus to #waitForOperand1
  201.   set foundItIsSalient to 0
  202.   set foundItButtonNr to 0
  203.   set bestresultSoFarStr to EMPTY
  204.   put bestresultSoFarStr into field "showprogress"
  205.   set nrofcalculations to 0
  206.   put toRoman(nrofcalculations) into field "calculationsfield"
  207.   set the castNum of sprite calculatorsnr to cast "smallCalculator"
  208.   updatescreenIfUserContinuesAFterFoundIt()
  209.   if clockIsActiveP then
  210.     resetTheClock()
  211.   end if
  212.   set operand2index to 0
  213.   set dividealertGivenP to 0
  214.   set minusalertGivenP to 0
  215. end
  216.  
  217. on stopMovie
  218.   repeat with n = 1 to nrOfStims
  219.     set the visible of sprite (zerobuttonsnr + ((n - 1) * 2) + 1) to 1
  220.     set the visible of sprite (zerobuttonsnr + (n * 2)) to 1
  221.   end repeat
  222.   set the stageColor to 210
  223.   updateStage()
  224. end
  225.  
  226. on showfirstRow
  227.   set firstRow to getAt(nrbuttontable, 1)
  228.   repeat with i = 1 to count(firstRow)
  229.     if initializedP then
  230.       set tempvalue to 0
  231.     else
  232.       set tempvalue to i
  233.     end if
  234.     setNrButtonvalue(getAt(firstRow, i), tempvalue)
  235.     showNrButton(getAt(firstRow, i))
  236.     shake(i)
  237.   end repeat
  238.   updateStage()
  239. end
  240.  
  241. on provideTheTask
  242.   set scorepossibleThisRoundP to 1
  243.   set firstRow to getAt(nrbuttontable, 1)
  244.   hideAllValues(firstRow)
  245.   SetAllselectable(firstRow, 0)
  246.   if not findProblemInDatabaseP then
  247.     gettargetnr()
  248.     getnrsfromset(nrOfStims)
  249.   else
  250.     put "before selectAProblem" & the ticks
  251.     selectAProblem()
  252.     put "after selectAProblem" & the ticks
  253.   end if
  254.   showtargetnr()
  255.   showset()
  256.   puppetSound(0)
  257.   SetAllselectable(firstRow, 1)
  258.   set the castNum of sprite spinnersnr to cast "dicescoop"
  259.   set the loc of sprite spinnersnr to point(505, 103)
  260.   updateStage()
  261.   waitawhile(10)
  262.   set the castNum of sprite spinnersnr to cast "dicedown"
  263.   set the loc of sprite spinnersnr to point(504, 103)
  264. end
  265.  
  266. on hideAllValues list
  267.   repeat with n = 1 to count(list)
  268.     hideNrButtonValue(getAt(list, n))
  269.   end repeat
  270.   updateStage()
  271. end
  272.  
  273. on SetAllselectable list, boolean
  274.   repeat with n = 1 to count(list)
  275.     setNrButtonSelectable(getAt(list, n), boolean)
  276.   end repeat
  277. end
  278.  
  279. on getnrsfromset howmany
  280.   set stimSet to []
  281.   repeat with i = 1 to howmany
  282.     set thisone to getAt(toDrawFromSet, random(lengthtoDrawFromSet))
  283.     add(stimSet, thisone)
  284.   end repeat
  285. end
  286.  
  287. on showset
  288.   set firstRow to getAt(nrbuttontable, 1)
  289.   repeat with i = 1 to count(stimSet)
  290.     set thisone to getAt(stimSet, i)
  291.     setNrButtonvalue(getAt(firstRow, i), thisone)
  292.     showNrButton(getAt(firstRow, i))
  293.     updateStage()
  294.   end repeat
  295. end
  296.  
  297. on gettargetnr
  298.   if easyP then
  299.     set targetnr to random(89) + 10
  300.   else
  301.     set targetnr to random(899) + 100
  302.   end if
  303. end
  304.  
  305. on showtargetnr
  306.   put toRoman(targetnr) into field "targetfield"
  307. end
  308.  
  309. on getobjectFromSnr snr
  310.   set theOne to snr - zerobuttonsnr
  311.   set theOne to (theOne + 1) / 2
  312.   return getAt(getAt(nrbuttontable, currentStep), theOne)
  313. end
  314.  
  315. on clickOnNrButton
  316.   put "clickonnrButton"
  317.   if justAborted or menuVisibleP then
  318.     return 
  319.   end if
  320.   if calcIsRunningP then
  321.     if (the mouseCast < 13) or (the mouseCast > 18) then
  322.       return 
  323.     end if
  324.     set snr to (the mouseCast - 2) * 2
  325.   else
  326.     set snr to the clickOn
  327.     if the clickOn = 0 then
  328.       return 
  329.     end if
  330.   end if
  331.   set whichObject to getobjectFromSnr(snr)
  332.   handleClickOnNrButton(whichObject)
  333.   updateStage()
  334. end
  335.  
  336. on handleClickOnNrButton nrButton
  337.   if currentInputStatus = #waitForOperand1 then
  338.     set operand1 to nrButton
  339.     pressButton(nrButton)
  340.     set currentInputStatus to #waitForOperator
  341.   else
  342.     if currentInputStatus = #waitForOperand2 then
  343.       if nrButton = operand1 then
  344.         put "button already pressed"
  345.         beep()
  346.       else
  347.         if (operator = ":") and ((the value of operand1 mod the value of nrButton) <> 0) then
  348.           if (the value of nrButton > the value of operand1) and ((the value of nrButton mod the value of operand1) = 0) then
  349.             set dummy to nrButton
  350.             set nrButton to operand1
  351.             set operand1 to dummy
  352.             set operand2 to nrButton
  353.             pressButton(nrButton)
  354.             handleOperation()
  355.             set currentInputStatus to #waitForOperand1
  356.             if not dividealertGivenP then
  357.               alert("You said" && the value of operand2 && " : " && the value of operand1 & ". But that's illegal: no fractions! So I swapped the operands for you.")
  358.               set dividealertGivenP to 1
  359.             end if
  360.           else
  361.             alert("Remainder of division must be equal to 0. So,             for example, 10 : 2 is legal, but 10 : 3 is illegal.")
  362.           end if
  363.         else
  364.           if (operator = "-") and ((the value of operand1 - the value of nrButton) < 0) then
  365.             set dummy to nrButton
  366.             set nrButton to operand1
  367.             set operand1 to dummy
  368.             set operand2 to nrButton
  369.             pressButton(nrButton)
  370.             handleOperation()
  371.             set currentInputStatus to #waitForOperand1
  372.             if not minusalertGivenP then
  373.               alert("You said" && the value of operand2 && " - " && the value of operand1 & ". But that's illegal: no negative numbers! So I swapped the operands for you.")
  374.               set minusalertGivenP to 1
  375.             end if
  376.           else
  377.             if (operator = "-") and ((the value of operand1 - the value of nrButton) = 0) then
  378.               alert("Result must be greater than 0.")
  379.             else
  380.               set operand2 to nrButton
  381.               pressButton(nrButton)
  382.               handleOperation()
  383.               set currentInputStatus to #waitForOperand1
  384.             end if
  385.           end if
  386.         end if
  387.       end if
  388.     else
  389.       if currentInputStatus = #waitForOperator then
  390.         unpressButton(operand1)
  391.         set currentInputStatus to #waitForOperand1
  392.         if the buttonsnr of operand1 <> the buttonsnr of nrButton then
  393.           handleClickOnNrButton(nrButton)
  394.         else
  395.           puppetSound("nrButtonClick")
  396.         end if
  397.       end if
  398.     end if
  399.   end if
  400. end
  401.  
  402. on clickOnOperator
  403.   put "clickonoperatr"
  404.   if justAborted or menuVisibleP then
  405.     return 
  406.   end if
  407.   if calcIsRunningP then
  408.     if (the mouseCast < 22) or (the mouseCast > 29) then
  409.       return 
  410.     end if
  411.     if the mouseCast < 26 then
  412.       set snr to the mouseCast - 17
  413.     else
  414.       set snr to the mouseCast - 21
  415.     end if
  416.   else
  417.     set snr to the clickOn
  418.     if the clickOn = 0 then
  419.       return 
  420.     end if
  421.   end if
  422.   set tempoperatorindex to snr - zerooperatorsnr
  423.   handleClickOnOperator(tempoperatorindex)
  424.   put "enter handle with .." & tempoperatorindex
  425.   updateStage()
  426. end
  427.  
  428. on handleClickOnOperator paramIndex
  429.   if currentInputStatus = #waitForOperand1 then
  430.     put "click on operator but waiting for operand 1"
  431.     if operand2index = 0 then
  432.       beep()
  433.       return 
  434.     else
  435.       set currentRow to getAt(nrbuttontable, currentStep)
  436.       set whichObject to getAt(currentRow, operand2index)
  437.       handleClickOnNrButton(whichObject)
  438.     end if
  439.   end if
  440.   if currentInputStatus = #waitForOperand2 then
  441.     unpressOperatorButton(operatorindex)
  442.     set currentInputStatus to #waitForOperator
  443.     if operatorindex <> paramIndex then
  444.       handleClickOnOperator(paramIndex)
  445.     else
  446.       puppetSound("operatorButtonClick")
  447.     end if
  448.   else
  449.     set operatorindex to paramIndex
  450.     set operator to getAt(operatorList, operatorindex)
  451.     pressOperatorButton(operatorindex)
  452.     set currentInputStatus to #waitForOperand2
  453.   end if
  454. end
  455.  
  456. on pressOperatorButton operatorindex
  457.   set snr to zerooperatorsnr + operatorindex
  458.   set the castNum of sprite snr to the castNum of sprite snr - 4
  459.   puppetSound("operatorButtonClick")
  460. end
  461.  
  462. on unpressOperatorButton operatorindex
  463.   set snr to zerooperatorsnr + operatorindex
  464.   set the castNum of sprite snr to the castNum of sprite snr + 4
  465. end
  466.  
  467. on handleOperation
  468.   set currentRow to getAt(nrbuttontable, currentStep)
  469.   set newRow to getAt(nrbuttontable, currentStep + 1)
  470.   repeat with i = 1 to nrOfStims
  471.     setNrButtonvalue(getAt(newRow, i), the value of getAt(currentRow, i))
  472.     setNrButtonVisibleP(getAt(newRow, i), the visibleP of getAt(currentRow, i))
  473.   end repeat
  474.   set operand1index to the listpos of operand1
  475.   setNrButtonvalue(getAt(newRow, operand1index), 0)
  476.   set result to calculateResult()
  477.   set operand2index to the listpos of operand2
  478.   setNrButtonvalue(getAt(newRow, operand2index), result)
  479.   set the loc of sprite tempresultbuttonsnr to the buttonloc of getAt(newRow, operand2index)
  480.   set the loc of sprite tempresultnrsnr to the nrloc of getAt(newRow, operand2index)
  481.   set the locH of sprite tempresultnrsnr to the locH of sprite tempresultnrsnr
  482.   fixLocForWrappedText(tempresultnrsnr, "tempresult", the nrloc of getAt(newRow, operand2index))
  483.   put toRoman(result) into field "tempresult"
  484.   showConnectorToResult(operand1index, operand2index)
  485.   updateStage()
  486.   waitawhile(40)
  487.   set the loc of sprite tempresultbuttonsnr to heaven
  488.   set the loc of sprite tempresultnrsnr to heaven
  489.   unpressButton(operand1)
  490.   unpressButton(operand2)
  491.   unpressOperatorButton(operatorindex)
  492.   setAllNrButtonsToDimmed(currentRow, 1)
  493.   setAllNrButtonTrails(1)
  494.   updateStage()
  495.   setNrButtonVisibleP(getAt(newRow, operand1index), 0)
  496.   applyAllInVisibleP(newRow)
  497.   repeat with n = 1 to nrOfStims
  498.     applyVisibleP(getAt(newRow, n))
  499.   end repeat
  500.   if result = targetnr then
  501.     repeat with n = 1 to nrOfStims
  502.       if n <> operand2index then
  503.         hideNrButton(getAt(newRow, n))
  504.       end if
  505.     end repeat
  506.   end if
  507.   setAllNrButtonTrails(0)
  508.   updateStage()
  509.   setAllNrButtonsToDimmed(newRow, 0)
  510.   updateStage()
  511.   repeat with n = 1 to nrOfStims
  512.     showNrButtonValue(getAt(newRow, n))
  513.     applyVisibleP(getAt(newRow, n))
  514.   end repeat
  515.   set the visible of sprite (zeroClearsnr + currentStep) to 1
  516.   set currentStep to currentStep + 1
  517.   if result = targetnr then
  518.     userFoundIt(getAt(newRow, operand2index))
  519.   end if
  520. end
  521.  
  522. on calculateResult
  523.   set nr1 to the value of operand1
  524.   set nr2 to the value of operand2
  525.   if operator = "+" then
  526.     return nr1 + nr2
  527.   else
  528.     if operator = "-" then
  529.       return nr1 - nr2
  530.     else
  531.       if operator = "x" then
  532.         return nr1 * nr2
  533.       else
  534.         if operator = ":" then
  535.           return nr1 / nr2
  536.         end if
  537.       end if
  538.     end if
  539.   end if
  540. end
  541.  
  542. on showConnectorToResult operand1index, operand2index, operatorindex
  543.   if operand1index > operand2index then
  544.     set offsetcastnum to 50
  545.   else
  546.     set offsetcastnum to 60
  547.   end if
  548.   set whichCast to offsetcastnum + abs(operand1index - operand2index)
  549.   set the castNum of sprite connectorsnr to whichCast
  550.   set the loc of sprite connectorsnr to the buttonloc of operand2
  551.   set the locH of sprite connectorsnr to the locH of sprite connectorsnr - 35
  552.   set the locV of sprite connectorsnr to the locV of sprite connectorsnr + 12
  553.   set the locH of sprite tempoperatorsnr to the locH of sprite connectorsnr
  554.   set the locV of sprite tempoperatorsnr to the locV of sprite connectorsnr
  555.   set the castNum of sprite tempoperatorsnr to 65 + operatorindex
  556.   updateStage()
  557.   add(connectorlocs, the loc of sprite connectorsnr)
  558.   add(connectorcastnums, the castNum of sprite connectorsnr)
  559.   add(opconnectorcastnums, the castNum of sprite tempoperatorsnr)
  560. end
  561.  
  562. on hideLastConnector
  563.   set the trails of sprite connectorsnr to 0
  564.   set the trails of sprite tempoperatorsnr to 0
  565.   updateStage()
  566.   if currentStep > 2 then
  567.     set the loc of sprite connectorsnr to getAt(connectorlocs, currentStep - 2)
  568.     set the loc of sprite tempoperatorsnr to the loc of sprite connectorsnr
  569.     deleteAt(connectorlocs, currentStep - 1)
  570.     set the castNum of sprite connectorsnr to getAt(connectorcastnums, currentStep - 2)
  571.     deleteAt(connectorcastnums, currentStep - 1)
  572.     set the castNum of sprite tempoperatorsnr to getAt(opconnectorcastnums, currentStep - 2)
  573.     deleteAt(opconnectorcastnums, currentStep - 1)
  574.   else
  575.     set the loc of sprite connectorsnr to heaven
  576.     set the loc of sprite tempoperatorsnr to heaven
  577.     set connectorlocs to []
  578.     set connectorcastnums to []
  579.   end if
  580.   updateStage()
  581.   set the trails of sprite connectorsnr to 1
  582.   set the trails of sprite tempoperatorsnr to 1
  583.   updateStage()
  584. end
  585.  
  586. on setAllNrButtonTrails value
  587.   repeat with n = 1 to 2 * nrOfStims
  588.     set the trails of sprite (zerobuttonsnr + n) to value
  589.   end repeat
  590. end
  591.  
  592. on setAllNrButtonsToDimmed arow, bool
  593.   repeat with n = 1 to count(arow)
  594.     dimNrButton(getAt(arow, n), bool)
  595.   end repeat
  596. end
  597.  
  598. on clickOnClear
  599.   put "clickonclear"
  600.   if justAborted or menuVisibleP then
  601.     return 
  602.   end if
  603.   set clickedsnr to getClickedClearSnr()
  604.   set the castNum of sprite clickedsnr to cast "clearButtonPressed"
  605.   updateStage()
  606.   if currentInputStatus = #waitForOperand2 then
  607.     unpressButton(operand1)
  608.     unpressOperatorButton(operatorindex)
  609.   else
  610.     if currentInputStatus = #waitForOperator then
  611.       unpressButton(operand1)
  612.     end if
  613.   end if
  614.   updatescreenIfUserContinuesAFterFoundIt()
  615.   set currentInputStatus to #waitForOperand1
  616.   set thelastvisibleclearbuttonsnr to zeroClearsnr + currentStep - 1
  617.   repeat with snr = thelastvisibleclearbuttonsnr down to clickedsnr
  618.     waitawhile(20)
  619.     puppetSound("slurp")
  620.     handleClear(snr)
  621.   end repeat
  622.   set operand2index to 0
  623.   updateStage()
  624. end
  625.  
  626. on getClickedClearSnr
  627.   if calcIsRunningP then
  628.     repeat with n = zeroClearsnr + 1 to zeroClearsnr + nrOfStims
  629.       if rollOver(n) then
  630.         return n
  631.       end if
  632.     end repeat
  633.   else
  634.     set snr to the clickOn
  635.     return snr
  636.   end if
  637. end
  638.  
  639. on hideLastClearButton snr
  640.   set the visible of sprite snr to 0
  641.   set the castNum of sprite snr to cast "clearButtonUnPressed"
  642. end
  643.  
  644. on handleClear clearbuttonsnr
  645.   setAllNrButtonsnrsLocsTo(heaven)
  646.   set currentRow to getAt(nrbuttontable, currentStep)
  647.   repeat with i = 1 to nrOfStims
  648.     setNrButtonVisibleP(getAt(currentRow, i), 1)
  649.   end repeat
  650.   hideLastConnector()
  651.   hideLastClearButton(clearbuttonsnr)
  652.   updateStage()
  653.   set previousRow to getAt(nrbuttontable, currentStep - 1)
  654.   repeat with i = 1 to nrOfStims
  655.     showNrButton(getAt(previousRow, i))
  656.     applyVisibleP(getAt(previousRow, i))
  657.     showNrButtonValue(getAt(previousRow, i))
  658.   end repeat
  659.   set currentStep to currentStep - 1
  660.   updateStage()
  661. end
  662.  
  663. on setAllNrButtonsnrsLocsTo p
  664.   repeat with n = 1 to 2 * nrOfStims
  665.     set the loc of sprite (zerobuttonsnr + n) to p
  666.   end repeat
  667. end
  668.  
  669. on clickOnCalculator
  670.   if (justAborted and firstabortprocessed) or menuVisibleP then
  671.     return 
  672.   end if
  673.   if not calcIsRunningP then
  674.     set the castNum of sprite calculatorsnr to cast "bigCalculatorOn"
  675.     set the loc of sprite nrOfCalcsSnr to nrOfCalcsLoc
  676.     updateStage()
  677.     if justAborted then
  678.       return 
  679.     end if
  680.     puppetSound("operatorButtonClick")
  681.     updateStage()
  682.     set calcIsRunningP to 1
  683.     set timeOnStartCalculator to the ticks
  684.     updateStage()
  685.     findsolution()
  686.   else
  687.     set the castNum of sprite calculatorsnr to cast "bigCalculatorOff"
  688.     updateStage()
  689.     set calcIsRunningP to 0
  690.     waitawhile(60)
  691.     if justAborted then
  692.       set firstabortprocessed to 1
  693.     end if
  694.   end if
  695.   updateStage()
  696. end
  697.  
  698. on clickOnClock
  699.   if justAborted or menuVisibleP then
  700.     return 
  701.   end if
  702.   if clockIsActiveP then
  703.     set clockIsActiveP to 0
  704.     set the visible of sprite fillbarsnr to 0
  705.     set the visible of sprite maxsecssnr to 0
  706.     set the visible of sprite timeOutLinesnr to 0
  707.     set the castNum of sprite clocksnr to cast "cloud"
  708.   else
  709.     set the visible of sprite fillbarsnr to 1
  710.     set the visible of sprite maxsecssnr to 1
  711.     set the visible of sprite timeOutLinesnr to 1
  712.     set clockIsActiveP to 1
  713.     set the castNum of sprite clocksnr to cast "sun"
  714.     resetTheClock()
  715.   end if
  716.   updateStage()
  717. end
  718.  
  719. on initRadioButtons
  720.   set the checkBoxAccess to 2
  721.   set the hilite of cast "60 secs" to 0
  722.   set the hilite of cast "120 secs" to 0
  723.   set the hilite of cast "180 secs" to 1
  724.   set the hilite of cast "240 secs" to 0
  725.   set the hilite of cast "6000 secs" to 0
  726.   repeat with n = 35 to 40
  727.     puppetSprite(n, 1)
  728.     set the loc of sprite n to heaven
  729.   end repeat
  730.   set lastbutton to 77
  731.   set nrOfSecsInMAxSecs to 180
  732.   put toRoman(nrOfSecsInMAxSecs) into field "maxsecs"
  733. end
  734.  
  735. on clickOnRadioButton
  736.   if justAborted or menuVisibleP then
  737.     return 
  738.   end if
  739.   if calcIsRunningP then
  740.     if (the mouseCast < 75) or (the mouseCast > 79) then
  741.       return 
  742.     end if
  743.     set snr to the mouseCast - 39
  744.   else
  745.     set snr to the clickOn
  746.   end if
  747.   if snr <> 0 then
  748.     set castn to the mouseCast
  749.     set the hilite of cast lastbutton to 0
  750.     set the hilite of cast castn to 1
  751.     updateStage()
  752.     set nrOfSecsInMAxSecs to getAt([60, 120, 180, 240, 6000], castn - 75 + 1)
  753.     put toRoman(nrOfSecsInMAxSecs) into field "maxsecs"
  754.     set lastbutton to castn
  755.     set deadlinePassed to 0
  756.     closeRadioButtonWindow()
  757.   end if
  758.   updateStage()
  759. end
  760.  
  761. on clickOnMaxSecs
  762.   if justAborted or menuVisibleP then
  763.     return 
  764.   end if
  765.   openRadioButtonWindow()
  766. end
  767.  
  768. on openRadioButtonWindow
  769.   set the loc of sprite 35 to point(570, 14)
  770.   repeat with n = 36 to 40
  771.     set the loc of sprite n to point(570, 19 + ((n - 36) * 17))
  772.   end repeat
  773.   updateStage()
  774. end
  775.  
  776. on closeRadioButtonWindow
  777.   waitawhile(45)
  778.   repeat with n = 35 to 40
  779.     set the loc of sprite n to heaven
  780.   end repeat
  781. end
  782.  
  783. on resetTheClock
  784.   puppetSound("ticktack")
  785.   spriteBox(fillbarsnr, the left of sprite fillbarsnr, the top of sprite fillbarsnr, 5 + the left of sprite fillbarsnr, the bottom of sprite fillbarsnr)
  786.   set timeAtReset to the ticks
  787.   set ticksPassed to 0
  788.   set deadlinePassed to 0
  789.   set the foreColor of field "maxsecs" to 193
  790. end
  791.  
  792. on updateFillBar
  793.   if not deadlinePassed then
  794.     set maxticks to 60 * nrOfSecsInMAxSecs
  795.     set ticksPassed to the ticks - timeAtReset
  796.     if ticksPassed > maxticks then
  797.       timeIsUp()
  798.     end if
  799.     set newlength to max(5, min(maxlengthFillbar, (ticksPassed + 0.01) / maxticks * maxlengthFillbar))
  800.     spriteBox(fillbarsnr, the left of sprite fillbarsnr, the top of sprite fillbarsnr, newlength + the left of sprite fillbarsnr, the bottom of sprite fillbarsnr)
  801.     if ticksPassed = (0.90000000000000002 * maxticks) then
  802.       puppetSound("ticktack")
  803.     end if
  804.     updateStage()
  805.   end if
  806. end
  807.  
  808. on timeIsUp
  809.   puppetSound("timeIsUp")
  810.   set deadlinePassed to 1
  811. end
  812.  
  813. on idle
  814.   set justAborted to 0
  815.   set firstabortprocessed to 0
  816.   if clockIsActiveP then
  817.     updateFillBar()
  818.   end if
  819. end
  820.  
  821. on initDatabase
  822.   set findProblemInDatabaseP to 1
  823.   set selectableProblems to []
  824.   set nrOfTextFields to 4
  825.   if easyP then
  826.     set prefixstr to "eproblems"
  827.   else
  828.     set prefixstr to "problems"
  829.   end if
  830.   repeat with n = 1 to nrOfTextFields
  831.     set fieldname to prefixstr & string(n)
  832.     set i to the number of lines in field fieldname
  833.     if line i of field fieldname = EMPTY then
  834.       set i to i - 1
  835.     end if
  836.     repeat with nn = 1 to i
  837.       add(selectableProblems, LineAndProblemNumberToIndex(nn, n))
  838.     end repeat
  839.   end repeat
  840. end
  841.  
  842. on selectAProblem
  843.   if (selectableProblems = []) or switchedP then
  844.     initDatabase()
  845.     set switchedP to 0
  846.   end if
  847.   set i to random(count(selectableProblems))
  848.   set index to getAt(selectableProblems, i)
  849.   set r to indexToLineAndProblemNumber(index)
  850.   set lnr to getAt(r, 1)
  851.   set pnr to getAt(r, 2)
  852.   if easyP then
  853.     set prefixstr to "eproblems"
  854.   else
  855.     set prefixstr to "problems"
  856.   end if
  857.   set fieldname to prefixstr & string(pnr)
  858.   set theline to line lnr of field fieldname
  859.   set targetnr to value(word 1 of theline)
  860.   set stimSet to []
  861.   repeat with n = 2 to 7
  862.     add(stimSet, value(word n of theline))
  863.   end repeat
  864.   set fakesolution to word 8 to the number of words in theline of theline
  865.   set fakesolution to parseStringOfNrsToRoman(fakesolution)
  866.   set stimSet to scramble(stimSet)
  867.   deleteAt(selectableProblems, i)
  868. end
  869.  
  870. on indexToLineAndProblemNumber i
  871.   set lnr to i mod 1000
  872.   set pnr to i / 1000
  873.   return [lnr, pnr]
  874. end
  875.  
  876. on LineAndProblemNumberToIndex lnr, pnr
  877.   return (pnr * 1000) + lnr
  878. end
  879.  
  880. on findsolution
  881.   set bestresultSoFar to 100000
  882.   set bestresultSoFarStr to EMPTY
  883.   put bestresultSoFarStr into field "showprogress"
  884.   set nrofcalculations to 0
  885.   put toRoman(nrofcalculations) into field "calculationsfield"
  886.   findsolution6(scramble(stimSet), EMPTY, nrOfStims)
  887. end
  888.  
  889. on waitawhile n
  890.   set t to the ticks
  891.   repeat while the ticks < (t + n)
  892.     nothing()
  893.   end repeat
  894. end
  895.  
  896. on scramble list
  897.   set nr to count(list)
  898.   repeat with n = 1 to nr
  899.     set pickOne to random(nr)
  900.     set list to swap(list, 1, pickOne)
  901.   end repeat
  902.   return list
  903. end
  904.  
  905. on swap list, i1, i2
  906.   set temp to getAt(list, i1)
  907.   setAt(list, i1, getAt(list, i2))
  908.   setAt(list, i2, temp)
  909.   return list
  910. end
  911.  
  912. on clickOnExit
  913.   if justAborted then
  914.     return 
  915.   end if
  916.   unpuppetall()
  917.   fillHiScore()
  918.   go("uitro")
  919. end
  920.  
  921. on clickOnExamples
  922.   if justAborted then
  923.     return 
  924.   end if
  925.   go("exampl")
  926. end
  927.  
  928. on clickOnExplainRules
  929.   if justAborted then
  930.     return 
  931.   end if
  932.   go("help")
  933. end
  934.  
  935. on doneWithRules
  936.   if justAborted then
  937.     return 
  938.   end if
  939.   go("play")
  940. end
  941.  
  942. on clickOnMenu
  943.   if justAborted then
  944.     return 
  945.   end if
  946.   if the castNum of sprite menusnr = 146 then
  947.     if easyP then
  948.       set the castNum of sprite menusnr to cast "menuopenFac"
  949.     else
  950.       set the castNum of sprite menusnr to cast "menuopenCom"
  951.     end if
  952.     set the loc of sprite menusnr to point(320, 324)
  953.     set menuVisibleP to 1
  954.   else
  955.     set the castNum of sprite menusnr to cast "menuclosed"
  956.     set the loc of sprite menusnr to point(353, 462)
  957.     set menuVisibleP to 0
  958.     if the mouseV < 291 then
  959.     else
  960.       if the mouseV < 338 then
  961.         clickOnExplainRules()
  962.       else
  963.         if the mouseV < 370 then
  964.           clickOnExamples()
  965.         else
  966.           if the mouseV < 402 then
  967.             clickOnEasy()
  968.           else
  969.             if the mouseV < 428 then
  970.               clickOnhard()
  971.             end if
  972.           end if
  973.         end if
  974.       end if
  975.     end if
  976.   end if
  977. end
  978.